package com.yc.rh.times;

import java.util.Timer;
import java.util.TimerTask;

import javax.servlet.http.HttpSession;

import com.yc.rh.utils.SessionAttributeNames;

public class MyTimer {
	private TimerTask task=null;
	private Timer timer=new Timer();
	
	public void getTimeer(final HttpSession session){
		task=new TimerTask(){
			@Override
			public void run() {
				session.setAttribute(SessionAttributeNames.CHECKCODE, "");
				session.removeAttribute(SessionAttributeNames.CHECKCODE);
				System.out.println("session清空完成");
			}
		};
		
		timer.schedule(task, 2*60*1000);  //2分钟后执行此方法一次
	}
	
	public void closeTimer(){
		if(timer!=null){
			timer.cancel();
		}
		
		if(task!=null){
			task.cancel();
		}
	}
}
